package com.appspot.yourvirtualgymtrainer;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.logging.Level;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.appengine.api.datastore.Entity;


public class GymDataServlet extends HttpServlet {
	
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			 throws ServletException,IOException {
		System.out.println("Wchodze do get");
		PrintWriter out = resp.getWriter();
		String gymDataType = req.getParameter("gymDataType");
	    Iterable<Entity> entities = GymData.getAllGymData(gymDataType);
	    if (entities != null) {
			resp.setContentType("application/json; charset=utf-8");
			resp.setHeader("Cache-Control", "no-cache");
		    out.println(Util.writeJSON(entities));
		    System.out.println(Util.writeJSON(entities));
	    }

	}
	
	protected void doPut(HttpServletRequest req, HttpServletResponse resp)
	    throws ServletException, IOException {
	  String gymDataType = req.getParameter("gymDataType");
	  String id = req.getParameter("id");
	  Map<String, String[]> parameters = req.getParameterMap();
	  
	  System.out.println(id);
	  System.out.println(gymDataType);
	  System.out.println(parameters);
	  GymData.updateGymData(gymDataType, id, parameters);
	  
		
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		    throws ServletException, IOException {
		
		
		System.out.println(req.getParameter("name"));

	}
	
}
